Skip to content

fix: activate SPI DMA for STM32H7 targets - #1367

Merged
nerdCopter merged 1 commit into
emuflight:masterfrom
nerdCopter:fix/h7-spi-dma-activation
Aug 10, 2026
Merged

fix: activate SPI DMA for STM32H7 targets#1367
nerdCopter merged 1 commit into
emuflight:masterfrom
nerdCopter:fix/h7-spi-dma-activation

Conversation

@nerdCopter

@nerdCopter nerdCopter commented Aug 7, 2026

Copy link
Copy Markdown
Member

AI Generated [pull-request]

Summary

Closes #1353.

spiInitBusDMA() (src/main/drivers/bus_spi.c) already guards
#if (defined(STM32F4) || defined(STM32F7) || defined(STM32H7)) && defined(USE_SPI) — H7
support exists in the function itself. PR #1348 only defined USE_SPI_DMA_ENABLE_LATE for
STM32F4/STM32F7 in common_fc_pre.h; H7 targets never reached the fc_init.c call
site (gated #if defined(USE_SPI) && defined(USE_SPI_DMA_ENABLE_LATE)), so spiInitBusDMA()
was dead code on every H7 target.

This PR adds the same define to the STM32H7 block, mirroring the existing F4/F7 pattern.
One line, one file.

No USE_GYRO_IMUF9001 target is STM32H7-based (HELIOSPRING/STRIXF10/MODE2FLUX are all
F4/F7), so this doesn't interact with the SPI1-exclusion guard PR #1359 added.

Tier classification

Tier 2 — behavioral change (DMA path activation), per this project's production-
readiness gates. All requirements verified on real STELLARH7DEV hardware — see below.

  • Gyro verified on: STELLARH7DEV (ICM42688P, on SPI3 — dma confirms SPI_SDI/SDO 3
    active; blackbox gyroADC/gyroUnfilt sane throughout a real hover flight)
  • Motor test: STELLARH7DEV — motor[0-3] full-range utilization (152–2047), no stuck
    values, during the same flight

Scope note: this physical board has 4 IMU footprints (ICM-42688-P, ICM-45686,
ICM-45605, ICM-40609-D, per the board schematic). EmuFlight only implements
ICM-42688-P on STELLARH7DEV (USE_GYRO_SPI_ICM42688P) — the other three have no EF
driver and no multi-IMU selection mechanism (USE_IMU1/USE_IMU2 is Betaflight-only,
doesn't exist in EF). All verification above is scoped to ICM-42688-P only.

Verification done

  • make clean && CCACHE_DISABLE=1 make test: 42/42 unit test binaries pass, 0 fail.
  • CCACHE_DISABLE=1 make STELLARH7DEV MATEKH743 KAKUTEH7: clean compile, zero warnings.
  • Link-map cross-reference on STELLARH7DEV: spiInitBusDMA is placed at a real address
    and cross-referenced from the LTRANS object — genuinely linked in under
    -Wl,-gc-sections, not just present-but-eliminated.
  • CodeRabbit GitHub review: raised a finding requesting H7 hardware validation before
    default-on, then withdrew it after re-tracing bus_spi.c/bus_spi_ll.c/
    dma_stm32h7xx.c/the H7 linker scripts — confirmed H7's DTCM/cache DMA constraints are
    already handled generically, same fallback-to-polling model as the accepted F4/F7
    precedent. Full exchange: PR review thread starting at
    fix: activate SPI DMA for STM32H7 targets #1367 (comment).

Real-hardware verification (STELLARH7DEV) — 2026-08-09

CLI dma/status/tasks, master vs. this branch, same board/config:

  • master (035fff1): zero SPI DMA anywhere (expected — no H7 call site existed yet).
  • This branch (461bee6): adds DMA1 Stream4/5 = SPI_SDO/SDI 3 (gyro, ICM42688P) and
    DMA1 Stream6/7 = SPI_SDO/SDI 4 (flash, W25M02G) — every pre-existing row (MOTOR 1-4
    on DMA1 Stream0-3, ADC on DMA2 Stream1) unchanged. Zero collision.
  • GYRO/PID timing: master avg 30µs/31.2% maxload vs. branch avg 29-31µs/30-35% maxload
    across multiple captures — no regression, consistent with DMA offloading transfer work.

3x flash + reboot power cycle: byte-identical dma table and consistent GYRO/PID
timing across all 3 boots — no init-time race.

Hover-flight test: blackbox log confirmed on this exact firmware build (461bee6,
STELLARH7DEV), ~39s flight. 0 failsafePhase non-IDLE rows across 63,965 samples; 1
momentary rxSignalReceived blip (negligible — same pattern seen in PR #1348's own flight
test); motor[0-3] full utilization, no stuck values; gyroUnfilt/gyroADC ranges sane
for the maneuvers flown.

Test plan

  • make test — 42/42 pass
  • Compile gate — STELLARH7DEV, MATEKH743, KAKUTEH7, zero warnings
  • Link-map confirms spiInitBusDMA genuinely activated on STELLARH7DEV
  • CodeRabbit GitHub review — code-level finding raised then withdrawn, no open findings
  • Gyro functional test on STELLARH7DEV — real hover flight, clean gyro data
  • Motor arming test on STELLARH7DEV — full-range utilization, no stuck values
  • Flash + reboot x3 on STELLARH7DEV — byte-identical DMA table each boot

spiInitBusDMA() (bus_spi.c) already guards STM32H7 alongside F4/F7, but
USE_SPI_DMA_ENABLE_LATE was only defined for STM32F4/STM32F7 in
common_fc_pre.h (PR emuflight#1348), so H7 targets never reached the fc_init.c
call site. Adds the same define for the STM32H7 block, matching the
existing F4/F7 pattern.

No STM32H7 USE_GYRO_IMUF9001 target exists, so this doesn't interact
with the SPI1-exclusion guard added by PR emuflight#1359.

Closes emuflight#1353
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The STM32H7 target configuration now enables USE_SPI_DMA_ENABLE_LATE alongside the existing H7 feature definitions.

Changes

STM32H7 SPI DMA configuration

Layer / File(s) Summary
Enable late SPI DMA feature
src/main/target/common_fc_pre.h
STM32H7 builds now define USE_SPI_DMA_ENABLE_LATE.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Possibly related PRs

Suggested labels: help wanted

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code change satisfies issue #1353 by enabling USE_SPI_DMA_ENABLE_LATE for STM32H7 targets.
Out of Scope Changes check ✅ Passed The pull request changes one relevant configuration line and contains no unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely describes the main change: enabling SPI DMA for STM32H7 targets.
Description check ✅ Passed The description explains the change, linked issue, scope, implementation details, and extensive test results.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nerdCopter

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot added the help wanted Extra attention is needed label Aug 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/target/common_fc_pre.h`:
- Line 100: Keep USE_SPI_DMA_ENABLE_LATE disabled by default or make it
explicitly opt-in until STELLARH7DEV validation is complete; record successful
gyro, motor, flash, and reboot hardware tests before enabling it for all USE_SPI
builds.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f2c4f02e-10ed-4d45-99df-a5b2360d6b2a

📥 Commits

Reviewing files that changed from the base of the PR and between 035fff1 and 461bee6.

📒 Files selected for processing (1)
  • src/main/target/common_fc_pre.h
📜 Review details
⏰ Context from checks skipped due to timeout. (12)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: build (targets-group-8)
  • GitHub Check: build (targets-group-10)
  • GitHub Check: build (targets-group-7)
  • GitHub Check: build (targets-group-4)
  • GitHub Check: build (targets-group-3)
  • GitHub Check: build (targets-group-6)
  • GitHub Check: build (targets-group-5)
  • GitHub Check: build (targets-group-11)
  • GitHub Check: build (targets-group-1)
  • GitHub Check: build (targets-group-9)
  • GitHub Check: build (targets-group-2)

Comment thread src/main/target/common_fc_pre.h
@nerdCopter
nerdCopter marked this pull request as ready for review August 10, 2026 14:35
@nerdCopter
nerdCopter merged commit 55618c3 into emuflight:master Aug 10, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SPI DMA activation: H7 targets not yet hardware-verified

1 participant